home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 76 / DVD Actual 1 Marzo 2003.iso / Trial / TurboCAD 7.1 Pro / Data.Cab / F24375_VPWnd.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-10  |  4.5 KB  |  213 lines

  1. // VPWnd.cpp : implementation file
  2. // TurboCAD SDK: new class implementation
  3.  
  4. #include "stdafx.h"
  5. #include "LTSample.h"
  6. #include "VPWnd.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CViewWnd
  16. // TurboCAD SDK: class created to manage view on dialog box
  17.  
  18. CViewWnd::CViewWnd() :
  19.     m_pView(NULL),
  20.     m_bStartSelect(FALSE),
  21.     m_pIDrawing(NULL)
  22. {
  23.     m_varTopLevel.vt = VT_BOOL;
  24.     m_varInvisible.vt = VT_BOOL;
  25.     m_varSegments.vt = VT_BOOL;
  26.     m_varArcs.vt = VT_BOOL;
  27.     m_varTexts.vt = VT_BOOL;
  28.     m_varBlocks.vt = VT_BOOL;
  29.  
  30.     m_varTopLevel.boolVal = FALSE;
  31.     m_varInvisible.boolVal = FALSE;
  32.     m_varSegments.boolVal = TRUE;
  33.     m_varArcs.boolVal = TRUE;
  34.     m_varTexts.boolVal = TRUE;
  35.     m_varBlocks.boolVal = TRUE;
  36. }
  37.  
  38. CViewWnd::~CViewWnd()
  39. {
  40.     SetView(NULL);
  41. }
  42.  
  43.  
  44. BEGIN_MESSAGE_MAP(CViewWnd, CWnd)
  45.     //{{AFX_MSG_MAP(CViewWnd)
  46.     ON_WM_PAINT()
  47.     ON_WM_LBUTTONDOWN()
  48.     ON_WM_ERASEBKGND()
  49.     //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51.  
  52. // TurboCAD SDK: set the view, if one already exists, delete and release it
  53. //               before assigning the new one.
  54. void CViewWnd::SetView(View* pView)
  55. {
  56.     if (m_pView != NULL)
  57.     {
  58.         // Delete view object
  59.         m_pView->Delete();
  60.  
  61.         // Decrement reference count
  62.         m_pView->Release();
  63.         m_pView = NULL;
  64.         if (m_pIDrawing != NULL)
  65.         {
  66.             m_pIDrawing->Release();
  67.             m_pIDrawing = NULL;
  68.         }
  69.     }
  70.  
  71.     if (pView == NULL)
  72.         return;
  73.  
  74.     m_pView = pView;
  75.  
  76.     // Increment reference count
  77.     m_pView->AddRef();
  78.  
  79.     m_pView->put_Update(FALSE);
  80.     // Map window to view
  81.     m_pView->put_HWND((long)m_hWnd);
  82.  
  83.     // Keep a reference to the drawing
  84.     m_pView->get_Drawing(&m_pIDrawing);
  85.  
  86.     // zoom to drawing extents and invalidate the window
  87.     ZoomAndInvalidate();
  88. }
  89.  
  90. BOOL CViewWnd::SetSelectMode()
  91. {
  92.     m_bStartSelect = ~m_bStartSelect;
  93.     return m_bStartSelect;
  94. }
  95.  
  96. IDrawing* CViewWnd::GetDrawing()
  97. {
  98.     if (m_pIDrawing != NULL)
  99.         m_pIDrawing->AddRef();
  100.     return m_pIDrawing;
  101. }
  102.  
  103. Graphics* CViewWnd::GetGraphics()
  104. {
  105.     Graphics* pGraphics = NULL;
  106.     if (m_pIDrawing != NULL)
  107.         m_pIDrawing->get_Graphics(&pGraphics);
  108.     return pGraphics;
  109. }
  110.  
  111. // TurboCAD SDK: zoom to drawing extents and invalidate the window
  112. void CViewWnd::ZoomAndInvalidate()
  113. {
  114.     // No view, exit
  115.     if (m_pView == NULL)
  116.         return;
  117.  
  118.     // Zoom to extents
  119.     HRESULT hRes = m_pView->ZoomToExtents();
  120.     if (FAILED(hRes))
  121.     {
  122. //        m_pView->put_Update(TRUE);
  123.     }
  124.  
  125.     // Invalidate window to force redraw
  126.     Invalidate();
  127. }
  128.  
  129. /////////////////////////////////////////////////////////////////////////////
  130. // CViewWnd message handlers
  131.  
  132. // TurboCAD SDK: override OnPaint to refresh the view
  133. void CViewWnd::OnPaint() 
  134. {
  135.     CPaintDC dc(this); // device context for painting
  136.     
  137.     if (m_pView == NULL)
  138.         return;
  139.  
  140.     // Force redraw of view window
  141.     HRESULT hRes = m_pView->Refresh();
  142.     if (FAILED(hRes))
  143.     {
  144.     }
  145. }
  146.  
  147. // TurboCAD SDK: override OnEraseBkgnd to reset the drawing area
  148. BOOL CViewWnd::OnEraseBkgnd(CDC* pDC) 
  149. {
  150.     CRect rect;
  151.     GetClientRect(rect);
  152.     pDC->FillSolidRect(rect, ::GetSysColor(COLOR_WINDOW));
  153.     return TRUE;
  154. }
  155.  
  156. void CViewWnd::OnLButtonDown(UINT nFlags, CPoint point) 
  157. {
  158.     if (m_bStartSelect)
  159.     {
  160.         Selection *pSel = NULL;
  161.         HRESULT hRes = m_pIDrawing->get_Selection(&pSel);
  162.         if (SUCCEEDED(hRes))
  163.         {
  164.             pSel->Unselect();
  165.             pSel->Release();
  166.         }
  167.  
  168.         double dblX, dblY;
  169.         m_pView->ScreenToView(point.x,point.y, &dblX,&dblY);
  170.  
  171.         COleVariant varAperture((const double&)0.1);
  172.         PickResult *pPickRes = NULL;
  173.  
  174.         hRes = m_pView->PickPoint(dblX, dblY,
  175.                                    &varAperture,
  176.                                    &m_varTopLevel,
  177.                                    &m_varArcs,
  178.                                    &m_varTexts,
  179.                                    &m_varSegments,
  180.                                    &m_varBlocks,
  181.                                    &m_varInvisible,
  182.                                    &pPickRes);
  183.         if (SUCCEEDED(hRes))
  184.         {
  185.             PickEntry *pPickEntry = NULL;
  186.             COleVariant varIndex((long)0);
  187.             hRes = pPickRes->get_Item(&varIndex,&pPickEntry);
  188.             if (SUCCEEDED(hRes))
  189.             {
  190.                 IGraphic *pIGr = NULL;
  191.                 hRes = pPickEntry->get_Graphic(&pIGr);
  192.                 if (SUCCEEDED(hRes))
  193.                 {
  194.                     hRes = pIGr->Select();
  195.                     if (SUCCEEDED(hRes))
  196.                     {
  197.                         AfxMessageBox(IDS_SYMBOLSELECTED);
  198.                     }
  199.                     else
  200.                         AfxMessageBox(IDS_CANNOTSELECTGRAPHIC);
  201.                     pIGr->Release();
  202.                 }
  203.                 pPickEntry->Release();
  204.             }
  205.             else
  206.                 AfxMessageBox(IDS_CANNOTGETPICKENTRY);
  207.             pPickRes->Release();
  208.         }
  209.         GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(IDC_SELECTSYMBOL, BN_CLICKED), 0);
  210.     }
  211.     CWnd::OnLButtonDown(nFlags, point);
  212. }
  213.